﻿
(function () {
    var forgot = {
        init: function () {
            var old = false;//旧密码
            var newp = false;//新密码
            var ispwd = false;//两次输入
            this.bindEvents();
        },
        bindEvents: function () {
            var self = this;
            //旧密码验证start
            $("#old-pwd").blur(function () {
                self.isPwdNull();
            });
            //新密码验证start
            $("#new-pwd").blur(function () {
                self.isnewPwdNull();
            });
            //两次输入密码是否一致验证
            $("#repeat-new-pwd").blur(function () {
               self.Pwd();
            });
            //确定按钮
            $(".pwd-btn").click(function () {
                self.submitPwd();
            });
            //关闭错误提示按钮
            $(".colse-tip-btn").click(function () {
                $(".pwd-tip-box").hide();
               // 
            });
        },
        //旧密码验证
        isPwdNull: function () {
            if ($("#old-pwd").val() == "") {
                $(".old-error").html("<font color='red'>*</font>");
                old = false;
            }
            else {
                old = true;
                $(".old-error").html("<font color='red'></font>");
            }
        },
        //新密码验证
        isnewPwdNull: function () {
            if ($("#new-pwd").val() == "") {
                $(".new-error").html("<font color='red'>*</font>");
                newp = false;
            }
            else {
                newp = true;
                $(".new-error").html("<font color='red'></font>");
            }
        },
        //两次输入密码是否一致验证
        Pwd: function () {
            if ($("#repeat-new-pwd").val() == "") {
                $(".repeat-error").html("<font color='red'>*</font>");
                ispwd = false;
            } else if ($("#repeat-new-pwd").val() != $("#new-pwd").val()) {
                $(".repeat-error").html("<font color='red'>"+_("不一致")+"</font>");
                ispwd = false;
            }
            else {
                ispwd = true;
                $(".repeat-error").html("<font color='red'></font>");
            }
        },
        //确定
        submitPwd: function () {
            var self = this;
            var oldpwd = $("#old-pwd").val();
            var newpwd = $("#new-pwd").val();
            var repeatnewpwd = $("#repeat-new-pwd").val();
            if (oldpwd=="" || newpwd =="" || repeatnewpwd=="" || newpwd!=repeatnewpwd) {
               	myApp.alert(_("请输入密码！"));
            }else {
                self.customerModifyPassword();
            }
        },
        //修改密码
        customerModifyPassword:function(){
            var requestCustomer = {};
            requestCustomer.UserID = UserID;
            requestCustomer.OldUserPassword = $("#old-pwd").val();
            requestCustomer.NewUserPassword = $("#new-pwd").val();
            $.ajax({
                url: "/Team/TeamModifyPassword",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(requestCustomer),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                    if (_result["msgcode"] == true) {
                    	myApp.alert(_('修改成功,请重新登录！'), function () {
	                    	if(is_app()){
	                        	var reset_json={};
	                        	reset_json.result=true;
	                      		reset_json.userId=UserID;
		                      	reset_json.pwd=$("#new-pwd").val();
	                        	reset_json.type="2";
	                        	YiYi_APP.resetPwd(JSON.stringify(reset_json));
	                    	} else {
		                        window.location.href = "/team/index";
	                        }
	                    });
                    } else {
                       myApp.alert(_result["msginfo"]);
                        if(is_app()){
                        	var reset_json={};
                        	reset_json.result=false;
                        	reset_json.msg=_result["msginfo"];
                        	YiYi_APP.resetPwd(JSON.stringify(reset_json));
                        }
                    }
                }
            });
        },
    };
    forgot.init();
})();
